package com;

import com.config.BeanConfig;
import com.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Map;

public class Application {
    public static void main(String[] args) {
        //有scan和register两种方式获取定义的bean，可直接在构造中传入包路径或配置类，构造中会自动refresh
        //此处为了演示原理选择了无参构造的方式，手动使用了两种方式并手动refresh
        AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext();
        context.scan("com.service");
        context.register(BeanConfig.class);
        context.refresh();

        testBean(context);
    }

    private static void testBean(ApplicationContext context) {
        UserService userService = context.getBean(UserService.class);
        System.out.println(userService.findUserById("").getName());
        System.out.println(context.getBean("sayHello",Map.class).get("say"));
    }
}
